﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace LINQToolKit.Configuration
{
    public class ConfigurationBase
    {
        public IDictionary<string, string> Parameters { get; set; }
        public IDictionary<string, string> Attributes { get; set; }

        public ConfigurationBase()
        {
            this.Parameters = new Dictionary<string, string>();
            this.Attributes = new Dictionary<string, string>();
        }

        public void InitializeFromElement(XElement element)
        {
            element.AssertNull("element");

            foreach (var item in element.Attributes())
            {
                this.Attributes.Add(item.Name.LocalName, item.Value);
            }

            var collection =
                from e in element.Elements()
                where !e.HasElements && !e.HasAttributes
                select e;

            foreach (var item in collection)
            {
                this.Parameters.Add(item.Name.LocalName, item.Value);
            }

            this.Initialize(element);
        }

        protected virtual void Initialize(XElement element)
        { 
            
        }
    }
}
